﻿var DIALOG_WIDTH = 350;
var DIALOG_HEIGHT = 180;
var _popup = null;

function OpenAlertPopup(title, message, fnOKCallback, width, height) {
	_popup = _initDialog(title, message, 'dialog', width, height);
	_popup.dialog('close');

    _popup.dialog({
        buttons: {
            Ok: function () {
            	$(this).dialog("close");
                if (typeof (fnOKCallback) == 'function') {
                    fnOKCallback();
                }
                
            }
              }
    });
             ShowModalDialog(_popup);
             return false;
}

function OpenConfirmPopup(title, message, fnYesCallback, fnNoCallBack, width, height) {
	_popup = _initDialog(title, message, 'dialog', width, height);
	_popup.dialog('close');
    _popup.dialog({
        buttons: {
        	Yes: function ()
        	{
        		$(this).dialog('close');
                if (typeof (fnYesCallback) == 'function') {
                    fnYesCallback();
                }
            },
            No: function () {
            	$(this).dialog('close');
                if (typeof (fnNoCallBack) == 'function') {
                    fnNoCallBack();
                }
                
            }
        }
    });
             ShowModalDialog(_popup);
             return false;
}

function OpenDivPopup(title, id, width, height) {
    _popup = _initDialog(title, null, id, width, height);
    return _popup;
}

function _initDialog(title, message, id, width, height)
{
   if (_isDefinedValue(id)) {
    	modalDialog = $('#' + id);
    	if (_isDefinedValue(message))
    	{
    		//modalDialog.html(message);
    		modalDialog.html("<p>" + message + "</p>");
    	}
    }
    else {
        modalDialog = $('<div class="modalDialog"></div>');
        if (_isDefinedValue(message)) {
            modalDialog.html(message);
        }
    }
    
    if (!_isDefinedValue(width)) {
        modalDialog.dialog({
            width: 'auto'
        });
    }
    else {
        modalDialog.dialog({
            width: width
        });
    }
    if (!_isDefinedValue(height)) {
        modalDialog.dialog({
            height: 'auto'
        });
    }
    else {
        modalDialog.dialog({
            height: height
        });
    }
    if (!_isDefinedValue(title)) {
        title = "Title";
    }
    modalDialog.dialog({
        modal: true,
        autoOpen: false,
		resizable: false,
        //Resize:false,       
        //width: width,
        title: title,
        close: function () {
            //$(this).dialog('destroy').remove();
        }
    });

    return modalDialog;
}

function _isDefinedValue(value) {
    if (value == null || typeof (value) == 'undefined') {
        return false;
    }
    return true;
}

function ShowModalDialog(modalDialog) {
	modalDialog.dialog('open');
}
